package view;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import javax.swing.JButton;
import javax.swing.JLabel;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;
/**
 * This class manages the New Meetings view window
 * 
 * The New meeting view displays text field and areas for a meeting and allows the user to enter
 * new values to them. 
 * 
 * @author buthainahaldosary
 * @since June 1,2013 * @version $Revision: 1.0 $

*/
public class NewMeetingView {

		/**
		 * Editable text field/areas for a meeting and  main container jpanel
		 */
		private JTextField topic, location, startDate,endDate, attendees;
		private JTextArea description;
		private JPanel jPanel;
		/**
		 * Save and send buttons.
		 */
		private JButton createBtn,cancelBtn;
		/**
		 * Date format to be used for displaying the date.
		 */
		private String dateFormat;
		/**
		 * Constructor that sets the date format and calls setup components.
		 */
		public NewMeetingView() {
			dateFormat = "yyyy.MMMMM.dd hh:mm aaa";
			setupComponents();
		}
		/**
		 * Methods that sets up the view by initializing the fields.
		 */
		private void setupComponents() {
			startDate = new JTextField();
			endDate = new JTextField();
			topic = new JTextField();
			location = new JTextField();
			attendees = new JTextField();
			description = new JTextArea();
			createBtn = new JButton("Create", IconsManager.getImageIcon("small/plus.png"));
			cancelBtn = new JButton("Cancel", IconsManager.getImageIcon("small/cross.png"));
			
		}
		/**
		 * Creates a JOption Pane with the components and displays it.
		 */
		public void showDialog(){
			startDate.setEditable(true);
			endDate.setEditable(true);
			topic.setEditable(true);
			location.setEditable(true);
			attendees.setEditable(true);
			description.setEditable(true);
			jPanel= new JPanel(new MigLayout("fillx, width 400:600:800"));
			JPanel details = new JPanel(new MigLayout("fillx", ""));
			JScrollPane descriptionScroll = new JScrollPane(description);
			details.add(new JLabel("Topic:"));
			details.add(topic, "wrap, growx");
			details.add(new JLabel("Location:"));
			details.add(location, "wrap, push, growx");
			details.add(new JLabel("Start Date:"));
			details.add(startDate, "wrap, growx");
			details.add(new JLabel("End Date:"));
			details.add(endDate, "wrap, growx");
			details.add(new JLabel("Attendees:"));
			details.add(attendees, "wrap, growx");
			details.add(descriptionScroll, "span 2, growx, h 50:200:400");
			jPanel.add(details,"wrap, growx");
			
			JPanel buttonsPanel = new JPanel(new MigLayout("fillx"));
			buttonsPanel.add(createBtn, "push, align right");
			buttonsPanel.add(cancelBtn, "align right");
			jPanel.add(buttonsPanel, "width 100%");
			
			//show as dialog
			ViewHelpers.showDialog(jPanel, "New Meeting");
		
		
		}
		
		
		/**
		 * 
		
		 * @return the topic as text. */
		public String getTopicText() {
			return topic.getText();
		}
		/**
		 * 
		
		 * @return the location as text. */
		public String getLocationText()
		{
		return location.getText();
		}
		/**
		 * 
		 * @param ts timestamp's text to be set
		 */
		public void setStartDate(Timestamp ts)
		{	String d = new SimpleDateFormat(dateFormat).format(ts);
			this.startDate.setText(d);
		}
		
		/**
		 * 
		 * @param ts timestamp's text to be set
		 */
		public void setEndDate(Timestamp ts)
		{	String d = new SimpleDateFormat(dateFormat).format(ts);
			this.endDate.setText(d);
		}
		/**
		 * 
		
		 * @return the start date as text */
		public String getStartDateText() {
			return startDate.getText();
		}
		/**
		 * 
		
		 * @return the end date as text */
		public String getEndDateText() {
			return endDate.getText();
		}
		/**
		 * 
		
		 * @return the attendees text. */
		public String getAttendeesText() {
			return attendees.getText();
		}
		/**
		 * 
		
		 * @return the description text */
		public String getDescriptionText() {
			return description.getText();
		}
		
		/**
		 * 
		
		 * @return the create button */
		public JButton getCreateBtn() {
			return createBtn;
		}
		/**
		 * Method getTopic.
		 * @return JTextField
		 */
		public JTextField getTopic() {
			return topic;
		}
		/**
		 * Method getLocation.
		 * @return JTextField
		 */
		public JTextField getLocation() {
			return location;
		}
		/**
		 * Method getStartDate.
		 * @return JTextField
		 */
		public JTextField getStartDate() {
			return startDate;
		}
		/**
		 * Method getEndDate.
		 * @return JTextField
		 */
		public JTextField getEndDate() {
			return endDate;
		}
		/**
		 * Method getAttendees.
		 * @return JTextField
		 */
		public JTextField getAttendees() {
			return attendees;
		}
		/**
		 * Method getDescription.
		 * @return JTextArea
		 */
		public JTextArea getDescription() {
			return description;
		}
		/**
		 * Method getDateFormat.
		 * @return String
		 */
		public String getDateFormat() {
			return dateFormat;
		}
		/**
		 * 
		
		 * @return the jpanel main container */
		public JPanel getPanel()
		{
			return jPanel;
		}
		/**
		 * 
		
		 * @return the JButton cancel button */
		public JButton getCancelBtn() {
			return cancelBtn;
		}
	
}
